{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1200, 800, 3)\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "1.load\n",
    "2.info\n",
    "3.resize\n",
    "4.check\n",
    "'''\n",
    "import cv2\n",
    "img = cv2.imread('../../imags/test.jpeg',1)\n",
    "imgInfo = img.shape\n",
    "print(imgInfo)\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "mode = imgInfo[2]\n",
    "# 1.放大 缩小\n",
    "# 2.等比例缩放和非等比例缩放\n",
    "dstHeight = int(height * 0.5)\n",
    "dstWidth = int(width * 0.5)\n",
    "\n",
    "##缩放\n",
    "## 最近邻域插值  双线性插值（默认）  像素关系重采样 立方插值\n",
    "dst = cv2.resize(img,(dstWidth,dstHeight))  #注意:输出尺寸格式为（宽，高）\n",
    "cv2.imshow('img',dst)\n",
    "cv2.waitKey(0)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 最近邻域插值 \n",
    "# src 10*20 dst 5*10\n",
    "# dst <- src  目标图像的每个点都来自原图像（1，2） <- (2,4)\n",
    "# dst x 1 -> src x 2 newX\n",
    "# newX = x*(src行/目标行) 【对应成比例，小数取临近值】\n",
    "\n",
    "\n",
    "## 双线性插值\n",
    "# 算法是针对邻域插值法计算后为小数时的计算\n",
    "# 【对应成比例，小数取附近四个点像素值的成比例取值】"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2 \n",
    "import numpy as np\n",
    "img = cv2.imread('../../imags/test.jpeg',1)\n",
    "imgInfo = img.shape\n",
    "print(imgInfo)\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "mode = imgInfo[2]\n",
    "dstHeight = int(height/2)\n",
    "dstWidth = int(width/2)\n",
    "dstImage = np.zeros((dstHeight,dstWidth,3),np.uint8) ##空白模板\n",
    "for i in range(0,dstHeight):\n",
    "    for j in range(0,dstWidth):\n",
    "        iNew = int(i*(height*1.0/dstHeight))\n",
    "        jNew = int(j*(width*1.0/dstWidth))\n",
    "        dstImage[i][j] =img[iNew,jNew]\n",
    "cv2.imshow('dst',dstImage)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
